

package org.t2.design.module.autogen;


public abstract class NameAbstractTable<T extends NameAbstractTable.NameCfg> extends org.gaming.design.loader.DesignCache<T> {

	@Override
	public final String fileName() {
		return "N-昵称库";
	}
	
	
	
	protected java.util.Map<String, java.util.List<T>> TypeCollector;
	
	/**
	 * 从容器索引中获取对象，获取不到会抛异常
	 */
	public final java.util.List<T> getInTypeCollector(
		int Type
	) {
		String key = "" + Type;
		java.util.List<T> ts = TypeCollector.get(key);
		if(ts == null) {
			throw new org.gaming.design.exception.DesignNotFoundException("Name when getInTypeCollector", key);
		}
		return ts;
	}
	
	/**
	 * 从容器索引中查找对象，获取不到会返回null
	 */
	public final java.util.List<T> findInTypeCollector(
		int Type
	) {
		String key = "" + Type;
		return TypeCollector.get(key);
	}
	
	/**
	 * 加载TypeCollector容器索引
	 */
	private final void loadTypeCollector() {
		java.util.Map<String, java.util.List<T>> TypeCollector = new java.util.HashMap<>();
		for(T data : all()) {
			String[] keys = new String[] {
				String.valueOf(data.getType()),
			};
			String key = String.join("_", keys);
			java.util.List<T> datas = TypeCollector.computeIfAbsent(key, k -> new java.util.ArrayList<>());
			datas.add(data);
		}
		this.TypeCollector = TypeCollector;
	}
	
	@Override
	protected final void loadAutoGenerate() {
	
		//加载容器索引
		loadTypeCollector();
		
	}
	
	public static class NameCfg {
		//类型1姓氏2名字
		protected int Type;
		/**
		 * get类型1姓氏2名字
		 */
		public int getType() {
			return Type;
		}
		//内容
		protected String Name;
		/**
		 * get内容
		 */
		public String getName() {
			return Name;
		}
	}

}